//前台调用
function $(_this){
	return new Base(_this);
}
//基础库
function Base(_this){
		 //创建一个数组 ,存放元素节点
        this.elements=[];
        if(_this!=undefined){
        	this.elements[0]=_this;
        }
}

	//获取ID节点
Base.prototype.getId=function(id){
		this.elements.push(document.getElementById(id));
		return this;
	}
//获取标签节点
Base.prototype.getTag=function(tag){
		var tags=document.getElementsByTagName(tag);
		for(var i=0;i<tags.length;i++){
				this.elements.push(tags[i]);	
		}
		return this;
	}
//获取class节点数组
Base.prototype.getClass=function(className,idName){
	var node=null;
	if(arguments.length==2){
		node=document.getElementById(idName);
	}else{
		node=document;
	}
		 var all=node.getElementsByTagName('*');
		 for(var i=0;i<all.length;i++){
			if(all[i].className==className){
				this.elements.push(all[i]);
			     }
			}
		return this;
	}
//添加addClass
Base.prototype.addClass=function(className){
		for(var i=0;i<this.elements.length;i++){
			if(!this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))){
				this.elements[i].className+=' '+className;	
		         }
			}
		return this;
	}
//移除removeClass
Base.prototype.removeClass=function(className){
		for(var i=0;i<this.elements.length;i++){
			if(this.elements[i].className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'))){
				this.elements[i].className=this.elements[i].className.replace(new RegExp('(\\s|^)'+className+'(\\s|$)'),' ');	
		         }
			}
		return this;
	}
//添加link或者style的CSS规则
Base.prototype.addRule=function(num,selectorText,cssText,position){
		var sheet=document.styleSheets[num];
		if(typeof sheet.insertRule != 'undefined'){
			sheet.insertRule(selectorText+'{'+cssText+'}',position);
		}else if(typeof sheet.addRule != 'undefined'){
			sheet.addRule(selectorText,cssText,position);
		}
		return this;
	}
//移除link或者style的CSS规则
Base.prototype.removeRule=function(num,position){
		var sheet=document.styleSheets[num];
		if(typeof sheet.deleteRule != 'undefined'){
			sheet.deleteRule(position);
		}else if(typeof sheet.removeRule != 'undefined'){
			sheet.removeRule(position);
		}
		return this;
	}
//获取数组内指定位置的元素节点
Base.prototype.getElement=function(num){
		 var element=this.elements[num];
		 this.elements=[];
		 this.elements[0]=element;
		 return this;
	}
//设置css
Base.prototype.css=function(attr,value){
	for(var i=0;i<this.elements.length;i++){	
		 //获取css样式	
			if(arguments.length==1){
		  return getStyle( this.elements[i],attr);
	             }
		 //设置css样式	
		this.elements[i].style[attr]=value;
	}
	return this;
}
//设置innerHTML
Base.prototype.html=function(value){

	for(var i=0;i<this.elements.length;i++){	
		 //获取innerHTML	
			if(arguments.length==0){
		  return  this.elements[i].innerHTML;
	             }
		 //设置innerHTML
		this.elements[i].innerHTML=value;
	}
	return this;
}
//触发点击事件
Base.prototype.click=function(fn){
	for(var i=0;i<this.elements.length;i++){	
		this.elements[i].onclick=fn;
	}
	return this;
}
//触发悬浮事件
Base.prototype.hover=function(over,out){
		for(var i=0;i<this.elements.length;i++){	
		this.elements[i].onmouseover=over;
		this.elements[i].onmouseout=out;
	}
	return this;
}
//设置显示
Base.prototype.show=function(){
		for(var i=0;i<this.elements.length;i++){	
		this.elements[i].style.display='block';
	}
	return this;
}
//设置隐藏
Base.prototype.hide=function(){
		for(var i=0;i<this.elements.length;i++){	
		this.elements[i].style.display='none';
	}
	return this;
}
//获取非行间样式
function getStyle(obj,attr){
    if(obj.currentStyle){            //兼容IE
        return  obj.currentStyle[attr];
    }else{
        return getComputedStyle(obj,false)[attr];  //标准W3C
    }

}
//设置元素居中
Base.prototype.center=function(){
	var left=(document.documentElement.clientWidth-350)/2;
    var top=(document.documentElement.clientHeight-250)/2;
   for(var i=0;i<this.elements.length;i++){
	
           this.elements[i].style.left=left+'px';
           this.elements[i].style.top=top+'px';
           
   }
   return this;
}
//响应窗口大小变事件 

Base.prototype.resize=function(fn){
	window.onresize=fn;
	return this;
}
